package com.lab.tools.ui;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.cuitrip.component.recyclerview.ItemClickSupport;
import com.cuitrip.service.R;
import com.lab.network.proxy.ApiProxy;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by ak on 3/21/16.
 */
public class LogListFragment extends Fragment {


    private View mContentView;

    @Bind(R.id.ct_recycler_view)
    RecyclerView mRecyclerView;

    private List<HttpLog> logList = new ArrayList<>();
    LogListAdapter adapter;

    public static final int REQUEST_CODE_GET_JSON = 0x01;

    /**
     * The Fragment's UI is just a simple text view showing its
     * instance number.
     */
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        mContentView = inflater.inflate(R.layout.log_list, container, false);
        ButterKnife.bind(this, mContentView);
        initData();
        return mContentView;
    }

    @OnClick(R.id.close_button)
    public void closeView() {
        if (getActivity() != null) {
            getActivity().finish();
        }
    }

    private void initData() {
        LinkedList<HttpLog> staticLogList = ApiProxy.httpLogList;
        for (HttpLog httpLog : staticLogList) {
            logList.add(httpLog);
        }
        adapter = new LogListAdapter(logList, getActivity());

        LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
        mRecyclerView.setLayoutManager(layoutManager);
        mRecyclerView.setAdapter(adapter);

        ItemClickSupport.addTo(mRecyclerView).setOnItemClickListener(new ItemClickSupport.OnItemClickListener() {
            @Override
            public void onItemClicked(RecyclerView recyclerView, int position, View v) {
                HttpLog httpLog = logList.get(position);


            }
        });
    }


}
